﻿
@{
    Layout = null;
    var mentity = ViewBag.mentity as SelectList;
    var dentity = ViewBag.dentity as SelectList;
} 
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link href="~/Content/Css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="~/Content/Css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="~/Content/Css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="~/Content/Css/animate.css" rel="stylesheet">
    <link href="~/Content/Css/style.css?v=4.1.0" rel="stylesheet">
    <title>Insert</title>
    <link href="/Content/Css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Content/common.css" rel="stylesheet"> 
</head>
<body>
    <div class="wrapper wrapper-content animated fadeInRight">
        <form class="form-horizontal m-t" id="mainForm">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">模块：</label>
                    <div class="col-xs-10">
                        <select class="form-control" name="ModuleID" id="ModuleID">
                            <option value=''>-请选择-</option>
                            @foreach (SelectListItem item in mentity.Items)
                            {
                                <option value='@item.Value'>@(item.Text)</option>
                            }
                        </select>
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请选择模块</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-2 control-label">动态：</label>
                    <div class="col-xs-10">
                        <select class="form-control" name="DynamicID" id="DynamicID">
                            <option value=''>-请选择-</option>
                            @foreach (SelectListItem item in dentity.Items)
                            {
                                <option value='@item.Value'>@(item.Text)</option>
                            }
                        </select>
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请选择动态</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-2 control-label">广告类型：</label>
                    <div class="col-xs-10">
                        <select class="form-control" name="AdvertisementType" id="AdvertisementType"> 
                            <option value=''>-请选择-</option>
                            <option value='1'>文字广告</option>
                            <option value='2'>图片广告</option>
                        </select>
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请填写广告类型</span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-2 control-label">广告信息：</label>
                    <div class="col-xs-10">
                        <input id="Text" name="Text" type="text" class="form-control">
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>请填写广告信息</span>
                    </div>
                </div>
                <div>
                    <button id="submit" class="btn btn-primary pull-right" type="submit">
                        <i class="fa fa-check"></i>&nbsp;提&nbsp;交
                    </button>
                </div>
            </div>
        </form>
    </div>


    <!-- 全局js -->
    <script type="text/javascript" src="~/Scripts/jquery.min.js?v=2.1.4"></script>
    <script type="text/javascript" src="~/Scripts/bootstrap.min.js?v=3.3.6"></script>
    <!-- jQuery Validation plugin javascript-->
    <script type="text/javascript" src="~/Scripts/plugins/validate/jquery.validate.min.js"></script>
    <script type="text/javascript" src="~/Scripts/plugins/validate/messages_zh.min.js"></script>
    <script type="text/javascript" src="~/Scripts/Extensions/ExtValidator.js"></script>

    <!-- layer javascript -->
    <script type="text/javascript" src="~/Scripts/plugins/layer/layer.min.js"></script>
    <script src="/Scripts/plugins/iCheck/icheck.min.js"></script>

    <script type="text/javascript">
        $(function () {
            $.validator.addMethod("selectNone", function (value, element) {
                return value == "0";
            }, "必须选择一项");


            var icon = "<i class='fa fa-times-circle'></i> ";
            var validator = $("#mainForm").validate({
                rules: {
                    ModuleID: { required: true },
                    DynamicID: { required: true, },
                    AdvertisementType: { required: true, },
                    text: { required: true, }, 
                },
                messages: {
                    ModuleID: { required: icon + "请选择模块" },
                    DynamicID: { required: icon + "请选择动态", },
                    AdvertisementType: { required: icon + "请选择类型", },
                    text: { required: icon + "请输入广告信息", }, 
                },
                submitHandler: function (form) {
                    $.ajax({
                        url: '/Advertisement/InsertAsync',
                        type: "post",
                        dataType: "json",
                        data: $('#mainForm').serialize(),
                        success: function (data) {
                            //Info,Success,Warning,Error
                            var type = data.type;
                            if (type == 1) {
                                layer.msg(data.content, { icon: 6, time: 2000 },
                                    function () {
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                    });

                            } else {
                                layer.msg(data.content, { icon: 5, time: 2000 });
                            }
                        }
                    });
                }
            });
        });
       
    </script>
</body>
</html>
